<template>
    <div>
        <h1>个人中心页</h1>
        <p>{{ $store.state.user }}</p>
        <button @click="remove">退出</button>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                msg: "1111",
            };
        },
        mounted() {
            console.log(this.msg);
            //this指向vue实例
        },
        beforeRouteEnter(to, from, next) {
            console.log(this);
            next((vm) => {
                console.log(vm.msg);
                if (vm.$store.state.user) {
                    next();
                } else {
                    next("/login");
                }
            });
        },
        methods: {
            remove(){
                localStorage.removeItem("token");
                this.$router.push({path: "/login"})
            }
        },
        //路由拦截 涉及到this的问题 需要在next里拿到this
    };
</script>